//
//  BGFuJiaoneCell.m
//  bigMall
//
//  Created by ios on 16/8/15.
//  Copyright © 2016年 thinklev. All rights reserved.
//

#import "BGFuJiaoneCell.h"
@interface BGFuJiaoneCell ()<UIPickerViewDelegate,UIPickerViewDataSource>{
    
    UIView *wancheng;
    
}
@property (nonatomic,strong) UIPickerView *picker;
@end
@implementation BGFuJiaoneCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

- (void)layoutSubviews {
    
    //picker
    self.picker = [[UIPickerView alloc] initWithFrame:CGRectMake(0, [UIApplication sharedApplication].keyWindow.bottom - [UIScreen mainScreen].bounds.size.height / 3, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height / 3)];
    
    self.picker.delegate = self;
    self.picker.dataSource = self;
    self.picker.backgroundColor = [UIColor whiteColor];
    self.picker.hidden = YES;
    self.picker.tag = 1;
    [self.picker selectRow:0 inComponent:0 animated:YES];
    [[UIApplication sharedApplication].keyWindow addSubview:self.picker];
    [self.picker showsSelectionIndicator];
    
    [self.picker reloadAllComponents];
    //创建确定的按钮
    wancheng = [[UIView alloc] initWithFrame:CGRectMake(0, self.picker.y - 30, [UIScreen mainScreen].bounds.size.width, 30)];
    wancheng.backgroundColor = [UIColor whiteColor];
    [[UIApplication sharedApplication].keyWindow addSubview:wancheng];
    
    UIView *a = [[UIView alloc] initWithFrame:CGRectMake(0, 29, [UIScreen mainScreen].bounds.size.width, 1)];
    a.backgroundColor = [UIColor lightGrayColor];
    [wancheng addSubview:a];
    
    UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(wancheng.width - [UIScreen mainScreen].bounds.size.width / 4.3, 0, [UIScreen mainScreen].bounds.size.width / 4.3, 30)];
    [btn setTitle:@"完成" forState:UIControlStateNormal];
    [btn setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
    btn .titleLabel.textAlignment = NSTextAlignmentRight;
    [btn addTarget:self action:@selector(btnClick) forControlEvents:UIControlEventTouchUpInside];
    wancheng.hidden = YES;
    [wancheng addSubview:btn];
    
}
- (void)jiazaishitu:(NSString *)stateType {
    
    if ([stateType isEqualToString:@"1"]) {
        
        self.textFiled.placeholder = @"请填写";
        
    }else {
        
        
        self.textFiled.userInteractionEnabled = NO;
        
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(pickera)];
        
        [self addGestureRecognizer:tap];
        
        
    }
    
}
- (void)pickera {
    
    wancheng.hidden = NO;
    self.picker.hidden = NO;
    
}
- (void)btnClick {
    
    wancheng.hidden = YES;
    self.picker.hidden = YES;
    
}
#pragma mark pickerDatasourece
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {
    
    return 1;
    
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
    
    return 3;
    
}
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
    
    
    return @"1";
    
    
}
- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view{
    UILabel* pickerLabel = (UILabel*)view;
    if (!pickerLabel){
        pickerLabel = [[UILabel alloc] init];
        // Setup label properties - frame, font, colors etc
        //adjustsFontSizeToFitWidth property to YES
        pickerLabel.minimumFontSize = 8;
        pickerLabel.adjustsFontSizeToFitWidth = YES;
        [pickerLabel setTextAlignment:NSTextAlignmentCenter];
        [pickerLabel setBackgroundColor:[UIColor clearColor]];
        [pickerLabel setFont:[UIFont boldSystemFontOfSize:18]];
    }
    // Fill the label text here
    pickerLabel.text=[self pickerView:pickerView titleForRow:row forComponent:component];
    return pickerLabel;
}
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
    
    
    self.textFiled.text = @"1";
    
}

@end
